"""
脚本名称：properties_handler.py
脚本功能：解析.properties配置文件
编写日期：日期
"""


class Properties(object):
    def __init__(self, file_name):
        self.fileName = file_name
        self.properties = {}

    def __get_dict(self, strName, dictName, value):
        dictName[strName] = value

    def get_properties(self):
        try:
            pro_file = open(self.fileName, 'Ur')
            for line in pro_file.readlines():
                line = line.strip().replace('\n', '')
                if line.find("#") != -1:
                    line = line[0:line.find('#')]
                if line.find('=') > 0:
                    strs = line.split('=')
                    strs[1] = line[len(strs[0]) + 1:]
                    v = strs[1].strip()
                    if v is None or v == "":
                        pass
                    else:
                        self.__get_dict(strs[0].strip(), self.properties, strs[1].strip())
        # except Exception, e:
        except Exception:
            #   raise e
            print('获取元素异常！')
        else:
            pro_file.close()
        return self.properties
